from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-29 14:08:26.956306
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 29, Apr, 2021
Time: 14:08:31
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.8570
Nobs: 276.000 HQIC: -48.5638
Log likelihood: 3332.54 FPE: 5.05120e-22
AIC: -49.0375 Det(Omega_mle): 3.66676e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.417942 0.120899 3.457 0.001
L1.Burgenland 0.075035 0.059989 1.251 0.211
L1.Kärnten -0.225459 0.053172 -4.240 0.000
L1.Niederösterreich 0.087385 0.129463 0.675 0.500
L1.Oberösterreich 0.229188 0.124555 1.840 0.066
L1.Salzburg 0.266718 0.068798 3.877 0.000
L1.Steiermark 0.112701 0.087369 1.290 0.197
L1.Tirol 0.121754 0.060486 2.013 0.044
L1.Vorarlberg -0.036660 0.055458 -0.661 0.509
L1.Wien -0.039555 0.112184 -0.353 0.724
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.452034 0.139984 3.229 0.001
L1.Burgenland 0.003888 0.069458 0.056 0.955
L1.Kärnten 0.330270 0.061565 5.365 0.000
L1.Niederösterreich 0.103485 0.149899 0.690 0.490
L1.Oberösterreich -0.065992 0.144217 -0.458 0.647
L1.Salzburg 0.220995 0.079658 2.774 0.006
L1.Steiermark 0.091707 0.101161 0.907 0.365
L1.Tirol 0.138369 0.070034 1.976 0.048
L1.Vorarlberg 0.150929 0.064212 2.350 0.019
L1.Wien -0.415610 0.129893 -3.200 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.275658 0.061366 4.492 0.000
L1.Burgenland 0.102920 0.030449 3.380 0.001
L1.Kärnten -0.013202 0.026989 -0.489 0.625
L1.Niederösterreich 0.079044 0.065713 1.203 0.229
L1.Oberösterreich 0.285972 0.063222 4.523 0.000
L1.Salzburg 0.016507 0.034921 0.473 0.636
L1.Steiermark 0.000073 0.044347 0.002 0.999
L1.Tirol 0.071771 0.030701 2.338 0.019
L1.Vorarlberg 0.073828 0.028149 2.623 0.009
L1.Wien 0.110165 0.056943 1.935 0.053
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.212079 0.058666 3.615 0.000
L1.Burgenland 0.027799 0.029109 0.955 0.340
L1.Kärnten 0.010571 0.025801 0.410 0.682
L1.Niederösterreich 0.053381 0.062821 0.850 0.395
L1.Oberösterreich 0.397719 0.060440 6.580 0.000
L1.Salzburg 0.078224 0.033384 2.343 0.019
L1.Steiermark 0.130419 0.042396 3.076 0.002
L1.Tirol 0.050230 0.029350 1.711 0.087
L1.Vorarlberg 0.081020 0.026911 3.011 0.003
L1.Wien -0.041953 0.054437 -0.771 0.441
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488443 0.114696 4.259 0.000
L1.Burgenland 0.097353 0.056911 1.711 0.087
L1.Kärnten 0.010439 0.050444 0.207 0.836
L1.Niederösterreich 0.005456 0.122820 0.044 0.965
L1.Oberösterreich 0.123330 0.118164 1.044 0.297
L1.Salzburg 0.055635 0.065268 0.852 0.394
L1.Steiermark 0.065573 0.082886 0.791 0.429
L1.Tirol 0.207584 0.057382 3.618 0.000
L1.Vorarlberg 0.033505 0.052612 0.637 0.524
L1.Wien -0.080173 0.106428 -0.753 0.451
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208125 0.090927 2.289 0.022
L1.Burgenland -0.010662 0.045117 -0.236 0.813
L1.Kärnten -0.006964 0.039990 -0.174 0.862
L1.Niederösterreich -0.018066 0.097368 -0.186 0.853
L1.Oberösterreich 0.422994 0.093677 4.515 0.000
L1.Salzburg 0.011287 0.051743 0.218 0.827
L1.Steiermark -0.026806 0.065710 -0.408 0.683
L1.Tirol 0.163523 0.045491 3.595 0.000
L1.Vorarlberg 0.055967 0.041709 1.342 0.180
L1.Wien 0.206194 0.084373 2.444 0.015
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222080 0.110199 2.015 0.044
L1.Burgenland 0.020608 0.054680 0.377 0.706
L1.Kärnten -0.070626 0.048466 -1.457 0.145
L1.Niederösterreich -0.063758 0.118004 -0.540 0.589
L1.Oberösterreich 0.020813 0.113531 0.183 0.855
L1.Salzburg 0.081882 0.062709 1.306 0.192
L1.Steiermark 0.324479 0.079637 4.074 0.000
L1.Tirol 0.461369 0.055132 8.368 0.000
L1.Vorarlberg 0.145384 0.050549 2.876 0.004
L1.Wien -0.139064 0.102255 -1.360 0.174
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208328 0.131734 1.581 0.114
L1.Burgenland 0.040104 0.065365 0.614 0.540
L1.Kärnten -0.075443 0.057937 -1.302 0.193
L1.Niederösterreich 0.110803 0.141065 0.785 0.432
L1.Oberösterreich 0.014338 0.135718 0.106 0.916
L1.Salzburg 0.195592 0.074964 2.609 0.009
L1.Steiermark 0.130065 0.095200 1.366 0.172
L1.Tirol 0.056120 0.065906 0.852 0.394
L1.Vorarlberg 0.106695 0.060428 1.766 0.077
L1.Wien 0.221554 0.122238 1.812 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.536426 0.072688 7.380 0.000
L1.Burgenland -0.013418 0.036067 -0.372 0.710
L1.Kärnten -0.015433 0.031968 -0.483 0.629
L1.Niederösterreich 0.097148 0.077837 1.248 0.212
L1.Oberösterreich 0.306044 0.074886 4.087 0.000
L1.Salzburg 0.013755 0.041363 0.333 0.739
L1.Steiermark -0.045055 0.052529 -0.858 0.391
L1.Tirol 0.082213 0.036366 2.261 0.024
L1.Vorarlberg 0.101898 0.033343 3.056 0.002
L1.Wien -0.059535 0.067448 -0.883 0.377
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.161101 0.094029 0.165734 0.219977 0.078091 0.085485 0.001410 0.158756
Kärnten 0.161101 1.000000 0.051116 0.208879 0.183510 -0.065619 0.175280 0.020699 0.304247
Niederösterreich 0.094029 0.051116 1.000000 0.246034 0.083370 0.323620 0.145131 0.022224 0.316694
Oberösterreich 0.165734 0.208879 0.246034 1.000000 0.304162 0.261017 0.096231 0.060460 0.140293
Salzburg 0.219977 0.183510 0.083370 0.304162 1.000000 0.150368 0.062039 0.089299 0.016855
Steiermark 0.078091 -0.065619 0.323620 0.261017 0.150368 1.000000 0.095866 0.099718 -0.098076
Tirol 0.085485 0.175280 0.145131 0.096231 0.062039 0.095866 1.000000 0.152885 0.153404
Vorarlberg 0.001410 0.020699 0.022224 0.060460 0.089299 0.099718 0.152885 1.000000 -0.009127
Wien 0.158756 0.304247 0.316694 0.140293 0.016855 -0.098076 0.153404 -0.009127 1.000000